<template>
	<view>
		
		<view class="u-flex user-box u-p-t-30 u-p-l-30 u-p-r-20 u-p-b-30">
			<view class="u-m-r-10 avatar-body">
				
				<oss-upload></oss-upload>
			</view>
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20">{{vuex_user.nickName}}</view>
				<view class="u-font-14 u-tips-color">用户名:{{vuex_user.username}}</view>
			</view>
			
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="个人信息" @click="toBaseInfo"></u-cell-item>
			</u-cell-group>
			
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="rmb-circle" title="所有订单" @click="toAllOrder"></u-cell-item>
				<u-cell-item icon="question-circle" title="退款/售后" @click="toReturns"></u-cell-item>
				<u-cell-item icon="star" title="商品收藏" @click="toCollect"></u-cell-item>
				<u-cell-item icon="map" title="收货地址" @click="toAddress"></u-cell-item>
			</u-cell-group>
		</view>
		
		<view class="u-m-t-20">
			
			<u-cell-group>
				<u-cell-item icon="reload" title="修改密码" @click="changepwd"></u-cell-item>
			</u-cell-group>
			<u-modal 
			v-model="tanchuangShow" 
			@confirm="tcConfirm" 
			@cancel="tcCancel" ref="uModal" 
			:content="content" 
			:show-title="showTitle" 
			:show-cancel-button='showCancleButton'></u-modal>
			<u-cell-group>
				<u-cell-item icon="close-circle" title="退出登录" @click="logout"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pic:'https://uviewui.com/common/logo.png',
				show:true,
				tanchuangShow:false,
				content: '确定退出',
				showTitle: false,
				showCancleButton: true
			}
		},
		onLoad() {
			if(!this.$u.utils.isLogin()) return
		},
		methods: {
			toReturns(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/order/returns'
				})
			},
			toCollect(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/center/userCollect'
				})
			},
			toAllOrder(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/center/allOrder'
				})
			},
			toAddress(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/address/index'
				})
			},
			toBaseInfo(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/center/baseInfo'
				})
			},
			changepwd(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				this.$u.route({
					url:'pages/center/changePwd'
				})
			},
			
			
			async logout(){
				if(!this.$u.utils.isLogin()){
					this.$u.toast("请先登录")
					return
				}// 如果没有登录先去登录
				//弹窗显示
				this.tanchuangShow = true;
				
			},
			async tcConfirm() {
				this.$u.toast('退出成功')
				this.tanchuangShow = false;
				//跳转到首页
				setTimeout(()=>{
					//清除缓存的token和用户信息
					this.$u.vuex('vuex_token',null)
					this.$u.vuex('vuex_user',{nickName: '欢迎登录咚咚图书商城',store: 'http://114.132.229.158:8088/'})
					this.$u.route({
						type: 'reLaunch',
						url: 'pages/index/index'
					})
				},1500)
			},
			tcCancel() {
				this.tanchuangShow = false;
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #ededed;
	}

	.camera{
		width: 54px;
		height: 44px;
		
		&:active{
			background-color: #ededed;
		}
	}
	.user-box{
		background-color: #fff;
	}
	.avatar-body{
		height: 70px;
		width: 70px;
	}
</style>

